Skip to main content

Rainfall Code

There are 7 functions in this python script.

  1. event_short_name: This function takes an event date, formats it, and returns a short name for the event.
  2. post_event_time: Given a DataFrame of events and the end of the time series data, this function calculates the time between the end of an event and the start of the next event.
  3. antecedent_event_time: This function calculates the time before an event, given a DataFrame of events and the start of the time series data.
  4. get_event_attributes: This function retrieves statistical attributes of events (e.g., return periods) compared to long-term records for a specified location. It uses an external NOAA service to obtain data.
  5. get_events: This function identifies and characterizes rainfall events from a rainfall DataFrame, defining events as periods of significant rainfall accumulation.
  6. write_swmm_rainfall_file: Given rainfall and event DataFrames, this function writes rainfall data to separate files for each event, possibly for use in a Storm Water Management Model (SWMM).
  7. Parse Date - this parses the date time from a string to a datetime object.

There are also a test event class that creates a unit test to run. This is where the code to run the script comes from.

The file path is declared. Currently this is set to read the rainfall.dat file but it is using the CSV parsing so should work on that as well. Parse the Date - This takes a date string and splits it into date and time sections and converts it to a datetime object. Reads the rainfall from the cs

Questions to be answered.

  1. Does this script with the Rainfall issues from the ticket CHAMA-47
  2. Is the output to this comparable to PCSWMM output.
  3. Does this accurately represent the data? What is the time Hourly, 15 min, 1 min.

TODO:

  1. Fix the Date Format while the CSV file can be read the date format of the CSV file is 2022-01-01 02:20, while the dat file is 11/25/2022 5:00 .
 def parse_date(date: str) -> datetime:
date_section, time_section = date.split(" ")
new_time_section = f'{time_section}:00'
date_time = pd.Timestamp(date_section) + pd.Timedelta(new_time_section)
return date_time
  1. Modify the code so that the rainfall has a proper main method.
  2. View in the debugger to see what exactly what is going on with the code.
  3. Review the code if there is anything I don't understand look it up.